import json
from api.base_service import BaseService

# 封装成会员服务类
class MemberService(BaseService):
    def __init__(self):
        # 调用父类init方法
        super().__init__()
        self.service_name="MemberService"

    def find_by_telephone(self,tel):
        resp=self.dubbo_client.invoke(self.service_name,"findByTelephone",tel)
        if resp=="Null":
            return None
        else:
            # 将string类型的数据，还原成字典或列表数据
            return json.loads(resp)

    def add(self,info):
        info["class"]="com.itheima.pojo.Member"
        resp=self.dubbo_client.invoke(self.service_name,"add",info)
        if resp=="Null":
            return True
        else:
            return False

    def find_member_count_by_months(self,months):
        resp=self.dubbo_client.invoke(self.service_name,"findMemberCountByMonths",months)
        return json.loads(resp)
